import $service from '../../../service.js';
var app = getApp();
Page({
    data:{
        isEsgin: $service.isEsgin,
        hisType: $service.isHis,
        iconListData:[
            {
              'icon_img' :'../../../static/images/bianzu.png',
              'icon_name':'就诊人管理',
              'icon_id' : '8'
            },
            // {
            //     'icon_img' :'../../../static/images/icon_personal_data@2x.png',
            //     'icon_name':'我的订单',
            //     'icon_id' : '6'
            // },
            {
                'icon_img' :'../../../static/images/icon_personal_data@2x.png',
                'icon_name':'个人资料',
                'icon_id' : '1'
            },
            //隐藏体质检测报告
            // {
            //     'icon_img' :'/static/images/icon_password@2x.png',
            //     'icon_name':'体质检测报告',
            //     'icon_id' : '7'
            // },
            {
                'icon_img' :'/static/images/icon_address@2x.png',
                'icon_name':'收货地址',
                'icon_id' : '7'
            },
            {
                'icon_img' :'../../../static/images/icon_help_center@2x.png',
                'icon_name':'帮助中心',
                'icon_id' : '2'
            },
            {
                'icon_img' :'../../../static/images/icon_privacy_agreement@2x.png',
                'icon_name':'隐私协议',
                'icon_id' : '3'
            },
            {
                'icon_img' :'../../../static/images/icon_password@2x.png',
                'icon_name':'修改密码',
                'icon_id' : '4'
            },
            {
                'icon_img' :'../../../static/images/icon_sign_out@2x.png',
                'icon_name':'退出登录',
                'icon_id' : '5'
            }
        ],
        isLoginshow:false,
        userInfo: {},
        Unread:false
    },
    onLoad(){
        //加载本页面的tabBar样式
        app.editTabBar1();
    },
    onShow(){
        wx.hideHomeButton()
        if (!$service.getStore('userInfo')){
            this.setData({
                isLoginshow : true
            })
        } else {
            this.setData({
                userInfo: JSON.parse($service.getStore('userData'))
            })
            // this.getUserInfo();
        }
    },
    // 获取个人信息
    getUserInfo() {
        app.http.getUserInfo().then(res => {
            let userInfo = res.data
            userInfo.userImg = userInfo.userImg ? userInfo.userImg : '../../../static/images/head.png'
            this.setData({
                userInfo
            })
        })
    },
    // 页面跳转
    gotopage(e){
        var num = e.currentTarget.dataset.num;
        var icon_id = e.currentTarget.dataset.icon_id;
        if(num == 3 && icon_id  == 2 || num == 3 && icon_id  == 3){
            if(icon_id == 2){
                $service.openPage('personal_novice_guide/personal_novice_guide')
            }else if(icon_id == 3){
                $service.openPage('../../login/agreement/agreement?type=1')
            }
        }else if(num == 4){
            $service.openPage('/pages/login/login')
        }else{
            if(this.data.isLoginshow ==true){//判断是否登录
                $service.loginuserid()
            }else{
                if(num == 0){
                    $service.openPage('personal_personalset/personal_personalset')
                }else if(num == 1){
                    $service.openPage('personal_interrogation/personal_interrogation')
                }else if(num == 2){
                    $service.openPage('personal_prescription/personal_prescription')
                } else if(num == 5){
                    $service.openPage('personal_report/personal_report')
                }else if(num == 3){
                    var icon_id = e.currentTarget.dataset.icon_id;
                    if(icon_id == 1){
                        $service.openPage('personal_personalset/personal_personalset')
                    }else if(icon_id == 4){
                        $service.openPage('personal_changepw/personal_changepw')
                    }else if(icon_id == 6){
                        // $service.openPage('../../prescription_flow/order_list/order_list') 
                        $service.openPage('../personal/personal_order_list/personal_order_list')  
                    }else if(icon_id == 5){
                        wx.showModal({
                            title: '温馨提示',
                            content: '确定要退出登录?',
                            success(res) {
                                if (res.confirm) {
                                    //登出
                                    app.http.outLogin().then(res => {
                                        app.webSocket.closeWebSocket();
                                        $service.removeStore('userInfo');
                                        $service.removeStore('miniToken');
                                        $service.removeStore('userData');
                                        wx.reLaunch({
                                            url: '/pages/user_index/user_index'
                                        })
                                    }).catch(err => {
                                        $service.showToast(err.msg)
                                    })
                                }
                            }
                        }) 
                    } else if (icon_id == 7) {
                        //隐藏体质检测报告地址
                        // $service.openPage('/pages/user_side/personal/personal_test_list/personal_test_list')  
                        $service.openPage('/pages/prescription_flow/receivie_address/receivie_address') 
                    } else if (icon_id == 8) {
                      $service.openPage('./patient_list/patient_list')  
                    }
                }
            }
        }
    },
})